home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15661 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  60 lines

  1. Path: ix.netcom.com!news
  2. From: guerino1@ix.netcom.com(Frank Guerino )
  3. Newsgroups: comp.lang.c++
  4. Subject: Inheritance: Accessing members of base classes for assignment in derived classes
  5. Date: 7 Apr 1996 03:31:52 GMT
  6. Organization: Netcom
  7. Message-ID: <4k7cv8$h4m@dfw-ixnews5.ix.netcom.com>
  8. NNTP-Posting-Host: wfd-nj1-04.ix.netcom.com
  9. X-NETCOM-Date: Sat Apr 06  9:31:52 PM CST 1996
  10.  
  11.  
  12. Hi,
  13.  
  14. I was wondering if someone would know how to translate a specific error
  15. message I'm getting.  I have a base class called "String" which is
  16. constructed in the following manner:
  17.  
  18.     class String{
  19.         char *str;
  20.     public:
  21.         String() {some initialization code...}
  22.         char *get() { return str; }
  23.         //...}
  24.  
  25. I have a derived class called "Instruction" which looks as follows:
  26.  
  27.     class Instruction : public String{
  28.         int data;
  29.     public:
  30.         Instruction() {initialization};
  31.         Instruction& operator=(const Instruction& x);
  32.         char *get_instruct() { return String::get(); }
  33.         //... }
  34.  
  35. I define the operator=() member as follows:
  36.  
  37.     Instruction& Instruction::operator=(const Instruction& x){
  38.         char *tmp;
  39.         strcpy(tmp, x.get_instruct());
  40.         data = x.data;
  41.         return *this;
  42.     }
  43.  
  44. When I compile, I get the error message:
  45.  
  46.     "cannot conver 'this' pointer from 'const class Instruction *' to
  47.     'class Instruction *const'
  48.  
  49. The error points to the "strcpy" statement in the operator=() member
  50. definition.
  51.  
  52. Does anyone know what this error means in plain English?  ...and how
  53. to fix it?
  54.  
  55. BTW, if it matters, I'm using Visual C++ 4.0.
  56. Extreme thanks!
  57.  
  58. Frank Guerino
  59. Guerino1@ix.netcom.com
  60.